'use strict';

angular.module('Report')

.factory('PersonOutputService', ['$q','$http', '$filter', function($q, $http, $filter) {
    return {
        getPersonOutputByDate: getPersonOutputByDate,
        getDetailPersonOutput:getDetailPersonOutput    
    };

    //获取个人产量表数据
    function getPersonOutputByDate (startDay, endDay, department) { 
        return http({
            method: 'POST',
            url: '/api/report/getPersonOutputByDate',
            data: {
                startDay: startDay,
                endDay: endDay,
                department: department      
            }
        });
    }
    

    //获取个人产量表数据详情
    function getDetailPersonOutput (startDay, endDay, department, userId) { 
        return http({
            method: 'POST',
            url: '/api/report/getDetailPersonOutput',
            data: {
                startDay: startDay,
                endDay: endDay,
                userId: userId,
                department: department      
            }
        });
    }

    function http (cfg) { 
        var deferred = $q.defer();

        $http(cfg).success(function(result) {
            if (result.Data) {
                deferred.resolve(result.Data);
            } else {
                deferred.reject(result.Error);
            }
        }).error(function(err) {
            deferred.reject(err);
        });

        return deferred.promise;
    }
    
}]);